package com.demo.heima;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * @author lkz
 * @className Test
 * @description
 * @date 2024/6/5 11:03
 **/
@Slf4j
public class Test {

    public static void main(String[] args) {
        /**
         * 方式 1
         */
        Thread thread = new Thread(){
            @Override
            public void run() {
                log.info("new Thread---");
            }
        };
        thread.start();

        /**
         * 方式二
         */
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                log.info("runnable---");
            }
        };
        Thread thread1 = new Thread(runnable);
        thread1.start();
        log.info("--------");
        new Thread(()->{
            log.info("lamda----");
        },"lamda").start();

        /**
         * 方式三
         */
        log.info("----方式三-----");
        MyCall myCall = new MyCall();
        FutureTask<String> stringFutureTask = new FutureTask<>(myCall);
        new Thread(stringFutureTask).start();
        try {
            System.out.println(stringFutureTask.get());
        }catch (Exception e){

        }


    }

}

class MyCall implements Callable<String>{
    @Override
    public String call() throws Exception {
        System.out.println("---callable---");
        return "123";
    }
}
